package com.nanhang.Controll;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nanhang.Service.Classesservice;
import com.nanhang.Service.Studentservice;
import com.nanhang.common.util.R;
import com.nanhang.entity.Classes;
import com.nanhang.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentControll {

    @Autowired
    private Studentservice studentService;

    @Autowired
    private Classesservice classesservice;

    @GetMapping("/list")
    public R findAllSTU(){
        List<Student> list = studentService.list();
        list.forEach(st -> {
            QueryWrapper<Classes> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("cid",st.getCid() );
            Classes classes = classesservice.getOne(queryWrapper);
            st.setCname(classes.getCname());
        });
        return R.ok().data("students",list);
    }

}
